package com.example.demo.config;
import com.example.demo.interceptor.LoginInterceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义拦截器配置类，实现WebMvcConfigurer接口，注入自定义的拦截器
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    /*
     *注册拦截器，设置拦截路径
     * 重写addInterceptors方法将我们自己新建的拦截器放入其中
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截的路径
        // registry.addInterceptor(getTestInterceptor()) .addPathPatterns("/**");
        //不拦截的路径
        // registry.addInterceptor(getTestInterceptor()) .excludePathPatterns(".....");


        registry.addInterceptor(loginInterceptor) .addPathPatterns("/recruit/**");

    }
}

